package ckw.database.repositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import ckw.database.model.Election;
import ckw.database.model.ElectionNonResidentVoter;
import ckw.database.model.Voter;

@Transactional
public interface ElectionNonResidentVoterRepository extends JpaRepository<ElectionNonResidentVoter, Long> {

	ElectionNonResidentVoter findByVoterAndElection(Voter voter, Election election);

	@Query("SELECT ev FROM ElectionNonResidentVoter ev WHERE ev.voter.identificationField = :voterId and ev.election.identificationField = :electionId")
	ElectionNonResidentVoter findByElectionIdAndVoterId(@Param("electionId") Long electionIdentificationField, @Param("voterId") String voterIdentificationField);
}
